import request from './axios'

// 产品相关API
export const productAPI = {
  // 获取产品列表
  getProducts: (params) => {
    return request({
      url: '/product/list',
      method: 'get',
      params
    })
  },
  
  // 获取单个产品
  getProduct: (id) => {
    return request({
      url: `/product/${id}`,
      method: 'get'
    })
  },
  
  // 创建产品
  createProduct: (data) => {
    return request({
      url: '/product',
      method: 'post',
      data
    })
  },
  
  // 更新产品
  updateProduct: (code, data) => {
    return request({
      url: `/product/${code}`,
      method: 'put',
      data
    })
  },
  
  // 删除产品
  deleteProduct: (code) => {
    return request({
      url: `/product/${code}`,
      method: 'delete'
    })
  },
  
  // 切换产品状态
  toggleProductStatus: (id, status) => {
    return request({
      url: `/product/${id}/status`,
      method: 'patch',
      data: { status }
    })
  },
  
  // 获取产品选择列表
  getProductChoices: (authMethod, accessMethod) => {
    return request({
      url: '/product/choice',
      method: 'get',
      params: {
        authMethod,
        accessMethod
      }
    })
  },
  
  // 获取产品的物模型属性
  getProductProperties: (productId) => {
    return request({
      url: `/product/${productId}/properties`,
      method: 'get'
    })
  }
}

export default productAPI